//
//  MOGetMarriedViewController.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/8/16.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOGetMarriedViewController.h"
#import "MOCommonUseViewCell.h"
#import "MOMyGetMarriedViewController.h"
#import "MOGetMarriedListViewController.h"

@interface MOGetMarriedViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,strong)UICollectionView *collectionView;

@property(nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation MOGetMarriedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initView];
    
    [self requestData];
    
}

- (void)initView{
    self.title = @"结亲";
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.collectionView];
}

-(void)requestData
{
    self.dataArray = [NSMutableArray array];
    NSArray *nameArr = @[@"我的结亲",@"结亲汇报"];
    NSArray *imageArr = @[@"wodejieqin",@"jieqinhuibao"];
    for (int i = 0; i<nameArr.count; i++) {
        MOCommonUseModel *model = [[MOCommonUseModel alloc]init];
        model.nameStr = nameArr[i];
        model.imageStr = imageArr[i];
        model.itemIndex = i;
        model.typeStr = @"3";
        //        model.countStr = @"99";
        [self.dataArray addObject:model];
    }
    [self.collectionView reloadData];
}

#pragma mark -UICollectionViewDataSource,UICollectionViewDelegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    MOCommonUseViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.model = self.dataArray[indexPath.item];
    return cell;
    
}
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    return CGSizeMake(SCREEN_WIDTH/3, SCREEN_WIDTH/3);
    
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
    
}

//定义每个UICollectionView 横向的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    return 0;
}

//定义每个UICollectionView 竖向的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    return 0;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    
    return CGSizeMake(0,0);
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.item==0) {//我的结亲
        MOMyGetMarriedViewController *vc = [[MOMyGetMarriedViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.item==1){//结亲汇报
        MOGetMarriedListViewController *vc = [[MOGetMarriedListViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}


#pragma mark -懒加载
-(UICollectionView *)collectionView
{
    if (!_collectionView) {
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-StatusBarAndNavigationBarHeight) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.alwaysBounceVertical = YES;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        
        [_collectionView registerClass:[MOCommonUseViewCell class] forCellWithReuseIdentifier:@"cell"];
        
    }
    return _collectionView;
}

@end
